package Stream;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class Stream1 {
    public static void main(String[] args) {
        stream1();
    }

    public static void stream1() {
        ArrayList<String> arrayList = new ArrayList<>();
        ArrayList<String> arrayList2 = new ArrayList<>();
        Collections.addAll(arrayList, "洛天依-15", "洛地衣-15", "洛天-16", "洛依-17", "洛天依捏-18");
        Collections.addAll(arrayList2, "乐正绫", "乐绫", "乐正零", "乐正", "乐正绫捏");
//        将洛开头，三个字的流出来
        arrayList.stream().filter(s -> s.startsWith("洛") && s.length() == 3).forEach(s -> System.out.print(s + " "));
        System.out.println();
//        将洛前三个跳过
        arrayList.stream().skip(3).forEach(s -> System.out.print(s + " "));
        System.out.println();
//        只要洛前三个
        arrayList.stream().limit(3).forEach(s -> System.out.print(s + " "));
        System.out.println();
//        合并洛绫
        Stream.concat(arrayList.stream(), arrayList2.stream()).forEach(s -> System.out.print(s + " "));
        System.out.println();
//        洛搜集到数组
        Object[] toArray = arrayList.stream().toArray();
        System.out.println(Arrays.toString(toArray));
//        洛搜集到map,保留age>16的
        Map<String, String> map = arrayList.stream().filter(s -> Integer.parseInt(s.split("-")[1]) > 16).collect(Collectors.toMap
                (s -> s.split("-")[0],
                        s -> s.split("-")[1])
        );
        System.out.println(map);
    }

}
